package com.java.frontweb.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.java.base.service.HttpAPIService;
import com.java.frontweb.pojo.Order;
import com.java.frontweb.pojo.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @ClassName UserService
 * @Description 用户登陆服务
 * @Author Trigger Wu
 * @Date 2018/9/2219:49
 * @Version 1.0
 **/
@Service
public class UserService {
    @Value("${CQZG_SSO_URL}")
    public String CQZG_SSO_URL;

    @Value("${CQZG_ORDER_URL}")
    public String CQZG_ORDER_URL;

    @Autowired
    private HttpAPIService apiService;

    private static final ObjectMapper Mapper = new ObjectMapper();
    
    /*
     *  根据token查询用户信息
     * 
     * @author Tigger Wu
     * @date 2018/9/22 22:49
     * @param 
     * @return 
     */
    public User queryByToken(String token) throws IOException {
        try {
            String url = CQZG_SSO_URL+"/rest/service/user/"+token;
            String jsonData = apiService.doGet(url);
            if(StringUtils.isNotEmpty(jsonData)){
                return Mapper.readValue(jsonData,User.class);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return  null;
    }
    

}
